-
-
Notifications
You must be signed in to change notification settings - Fork 442
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(table): Respect falsy value for addDuplicateNumbers #672
Conversation
See also #671 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logic checks out @thelindat
Thank you for the detailed explanation @tom-osborne |
imports/table/shared.lua
Outdated
@@ -85,7 +85,7 @@ end | |||
---@return table | |||
---Merges two tables together. Defaults to adding duplicate keys together if they are numbers, otherwise they are overriden. | |||
local function table_merge(t1, t2, addDuplicateNumbers) | |||
addDuplicateNumbers = addDuplicateNumbers ~= nil and addDuplicateNumbers or true | |||
addDuplicateNumbers = addDuplicateNumbers == nil and true or addDuplicateNumbers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addDuplicateNumbers = addDuplicateNumbers == nil or addDuplicateNumbers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thelindat Changes made as requested. Thanks
The logic for the third parameter (
addDuplicateNumbers
) does not respect a falsy value.When a value of
false
is passed the logic is resolved as follows:addDuplicateNumbers ~= nil
resolves totrue
addDuplicateNumbers ~= nil and addDuplicateNumbers
is therefore the same astrue and false
which resolves tofalse
addDuplicateNumbers ~= nil and addDuplicateNumbers or true
is therefore the same afalse or true
, which resolves totrue
So a falsy value always coerces to
true
.Simple test script:
Proposed solution is to reverse the logic somewhat so it sets the value to
true
only whennil
.Running the same test script: